/**
 * Created by Qarluq on 15/7/2.
 */

function change_code(obj){
    $("#code").attr("src",URL+Math.random());
    return false;
}
$(function(){
    $('.panel-group').hide();
    $('.group_1'). slideDown('slow');

    $('.top_li').click(function(){
        $('.top_left_ul li').removeClass('btn_top_act');
        $(this).addClass('btn_top_act');
        return;
    });

    $("#save").click(function () {
        var san=0;
        $(".text").each(function () {

            if ($(this).val() ==''||$(this).val() ==null) {
                san=1;
            }
        });
        if(san==0) {
            $("#add-form").attr('onsubmit',true);
        }
        if(san==1){
            alert("一个都不能为空");
            return;
        }
    });

    $('#button_1').click(salam_1);
    $('#button_2').click(salam_2);
    $('#button_3').click(salam_3);
    $('#button_4').click(salam_4);
    $('#button_6').click(salam_6);
    $('#button_5').click(salam_5);
    $('#button_7').click(salam_7);
    $('#button_8').click(salam_8);
});
function salam_1(){
    $('.panel-group').hide();
    $('.group_1'). slideDown('slow');
}
function salam_2(){
    $('.panel-group').hide();
    $('.group_2').slideDown('slow');
}
function salam_3(){
    $('.panel-group').hide();
    $('.group_3').slideDown('slow');
}
function salam_4(){
    $('.panel-group').hide();
    $('.group_4').slideDown('slow');
}
function salam_6(){
    $('.panel-group').hide();
    $('.group_6').slideDown('slow');
}
function salam_8(){
    $('.panel-group').hide();
    $('.group_8').slideDown('slow');
}function salam_7(){
    $('.panel-group').hide();
    $('.group_7').slideDown('slow');
}function salam_5(){
    $('.panel-group').hide();
    $('.group_5').slideDown('slow');
}

function del(){
    var gnl=confirm("你真的确定要删除吗?");
    if (gnl){
        return true;
    }
    else{
        return false;
    }
}

/*图片上去*/

function setImagePreview() {
    var docObj=document.getElementById("doc");
    var imgObjPreview=document.getElementById("preview");
    if(docObj.files && docObj.files[0]){
//火狐下，直接设img属性
        // imgObjPreview.style.display = 'block';
        imgObjPreview.style.width = '140px';
        imgObjPreview.style.height = '35px';
//imgObjPreview.src = docObj.files[0].getAsDataURL();
//火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
        imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
    }else{
//IE下，使用滤镜
        docObj.select();
        var imgSrc = document.selection.createRange().text;
        var localImagId = document.getElementById("localImag");
//必须设置初始大小
        localImagId.style.width = "140px";
        localImagId.style.height = "35px";
//图片异常的捕捉，防止用户修改后缀来伪造图片
        try{
            localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
            localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
        }catch(e){
            alert("您上传的图片格式不正确，请重新选择!");
            return false;
        }
        imgObjPreview.style.display = 'none';
        document.selection.empty();
    }
    return true;
}